package com.carpark.ejb.Model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Sawior
 */
@Entity
@Table(name = "parks")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ParksModel.findAll", query = "SELECT p FROM ParksModel p"),
    @NamedQuery(name = "ParksModel.findByParkId", query = "SELECT p FROM ParksModel p WHERE p.parkId = :parkId"),
    @NamedQuery(name = "ParksModel.findByParkDate", query = "SELECT p FROM ParksModel p WHERE p.parkDate = :parkDate"),
    @NamedQuery(name = "ParksModel.findByClient", query = "SELECT bm FROM ParksModel bm INNER JOIN  bm.parkingPassId s INNER JOIN s.passesrecordsModelCollection d WHERE d.clientId = :clientId"),
    @NamedQuery(name = "ParksModel.findByClientAndType", query = "SELECT bm FROM ParksModel bm INNER JOIN  bm.parkingPassId s INNER JOIN s.passesrecordsModelCollection d WHERE d.clientId = :clientId AND bm.type = :type"),
    @NamedQuery(name = "ParksModel.findByType", query = "SELECT p FROM ParksModel p WHERE p.type = :type")})
public class ParksModel implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ParkId")
    private Integer parkId;
    @Basic(optional = false)
    @NotNull
    @Column(name = "ParkDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date parkDate;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 6)
    @Column(name = "Type")
    private String type;
    @JoinColumn(name = "ParkingPassId", referencedColumnName = "ParkingPassId")
    @ManyToOne(optional = false)
    private ParkingpassesModel parkingPassId;

    public ParksModel() {
    }

    public ParksModel(Integer parkId) {
        this.parkId = parkId;
    }

    public ParksModel(Date parkDate, String type) {
        this.parkDate = parkDate;
        this.type = type;
    }

    public ParksModel(Integer parkId, Date parkDate, String type) {
        this.parkId = parkId;
        this.parkDate = parkDate;
        this.type = type;
    }

    public Integer getParkId() {
        return parkId;
    }

    public void setParkId(Integer parkId) {
        this.parkId = parkId;
    }

    public Date getParkDate() {
        return parkDate;
    }

    public void setParkDate(Date parkDate) {
        this.parkDate = parkDate;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public ParkingpassesModel getParkingPassId() {
        return parkingPassId;
    }

    public void setParkingPassId(ParkingpassesModel parkingPassId) {
        this.parkingPassId = parkingPassId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (parkingPassId != null ? parkingPassId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ParksModel other = (ParksModel) obj;
        if (this.parkId != other.parkId) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.carpark.ejb.Model.ParksModel[ parkId=" + parkId + " ]";
    }

}
